import type { IAccount } from '@/views/login/types'
import hyRequest from '..'
import { role_menu } from './data'

export function accountLogin(data: IAccount) {
  return hyRequest.post({
    url: '/login',
    data
  })
}

/**
 * @description: 获取用户信息
 * @param {string} id
 */
export function getUserInfoById(id: string) {
  return hyRequest.get({
    url: '/users/' + id
  })
}

export function accountLoginMock(data: IAccount) {
  console.log('data: ', data)
  return Promise.resolve({
    code: 0,
    data: {
      id: '1',
      name: 'admin',
      token:
        'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiIxODkyNTAxNzE1Mzc5NjkxNTIzIiwiY2xpZW50VHlwZSI6IldlYiIsImNsaWVudElkIjoid2ViIiwidG9rZW5UeXBlIjoiQUNDRVNTIiwiZXhwIjoxNzQxNzgxMzU4LCJpYXQiOjE3NDE3ODEwNTgsImp0aSI6ImY3MjM0YTc1LTJkNTMtNDFjYi1iNDRjLTU3MTI3MDk1ZDk4MCJ9.WDtNZqpnoQwH6CgPpB-BTnIxOIB90Um4QMt1XHN-sVQ'
      // token: 'admin-token'
    }
  })
}
export function getUserInfoByIdMock(id: string) {
  const data = {
    '1': {
      id: 1,
      name: 'coderwhy',
      realname: 'coderwhy',
      cellphone: 18812345678,
      enable: 1,
      createAt: '2021-01-02T10:20:26.000',
      ZupdateAt: '2021-01-03T04:50:13.000Z',
      role: {
        id: 1,
        name: '超级管理员',
        intro: '所有权限',
        createAt: '2021-01-02T10:01:52.000Z',
        updateAt: '2021-01-02T10:01:52.000Z',

        department: {
          id: 1,
          name: '总裁办',
          parentId: null,
          createAt: '2021-01-02T10:03:09.000Z',
          updateAt: '2021-01-05T08:25:46.000Z',
          leader: 'coderwhy'
        }
      }
    }
  }
  return Promise.resolve({
    code: 0,
    data: data[id as '1']
  })
}

/**
 * 根据角色id获取菜单menu
 */
export function getMenuListByRoleId(id: number) {
  return hyRequest.get({
    url: `/menus/${id}/menu`
  })
}

export function getMenuListByRoleIdMock(roleId: number) {
  console.log('roleId: ', roleId)
  return Promise.resolve({
    code: 0,
    data: role_menu
  })
}
